Page({
  data:{
    selects:[],
    selectAlbums:[],
    albums:[]
  },
  pictit: function () {
    wx.navigateTo({
      url: '../pictit/pictit',
    })
  },
  loadsing: function () {
    var that = this;
    for(var i=0;i<that.data.album.length;i++){
      if (that.data.album[i].selects=='bg_green'){
        that.data.selectAlbums.push(that.data.album[i].url);
      }
    }
    console.log(that.data.selectAlbums);
    getApp().globalData.selectAlbums = that.data.selectAlbums;
    if (getApp().globalData.selectAlbums.length==0){
      wx.showToast({
        title: '请至少选择一张图片',
        icon: 'none',
        duration: 1000
      })
      return;
    }
    wx.request({
      url: getApp().globalData.API_URI + '/index.php/face_dynamicAlbum',
      data: {
        openid: getApp().globalData.openid,
        imgs: getApp().globalData.selectAlbums,
        people_type: getApp().globalData.people_type1
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (res) {
        console.log(res.data);
        var insert_id = res.data.insert_id;
        if (getApp().globalData.people_type1 == '女生') {
          wx.navigateTo({
            url: '../album/album?id=' + insert_id,
          })
        } else {
          wx.navigateTo({
            url: '../albums/albums?id=' + insert_id,
          })
        }
      }
    });
    
    
  },
  choose:function(e){
    var that = this;
    console.log(e);
    var index = e.currentTarget.dataset.id;
    if (that.data.album[index].selects=='bg_black'){
      that.setData({ ['album[' + index + '].selects']: 'bg_green', });
    }else{
      that.setData({ ['album[' + index + '].selects']: 'bg_black', });
    }
  },
  noChoose:function(e){
    console.log("66666")
    var that =this;
    for(var i=0;i<that.data.album.length;i++){
      that.setData({ ['album[' + i + '].selects']: 'bg_black', });
    }
  },
  onShow:function(){
    var that = this;
    that.data.selectAlbums = [];
  },
  onLoad:function(options){
    var album = getApp().globalData.changePics;
    var img_url1 = [];

    for (var i = 0; i < album.length; i++) {
      var obj = {};
      var img_url = album[i].split("=====");
      //var img_url = img_url[0];
      obj.url = img_url[0];
      obj.title = img_url[2];
      obj.selects = 'bg_black';
      img_url1.push(obj);


    }
    this.setData({ album: img_url1 });
    console.log("这是回调回来的图片");
    console.log(this.data.album);
    getApp().globalData.selectAlbums = '';
  }
})